package cn.yunhe.service;

import cn.yunhe.dao.IEmpDao;
import cn.yunhe.entity.Emp;
import cn.yunhe.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("empService")
public class EmpService {

    @Resource(name = "empDao")
    private IEmpDao empDao;

    public void addEmp(Emp emp) {
        empDao.addEmp(emp);
    }

    public void delEmp(Emp emp){
        empDao.delEmp(emp);
    }

    public void update(Emp emp){
        empDao.updateEmp(emp);
    }

    public Emp getEmpInfoByName(String username){
        return empDao.getEmpInfoByName(username);
    }

    public IEmpDao getEmpDao() {
        return empDao;
    }

    public void setEmpDao(IEmpDao empDao) {
        this.empDao = empDao;
    }

    public Map<String,Object> getEmpInfo(int pageIndex){
        Map<String,Object> map = new HashMap<String, Object>();
        int totalRows = empDao.countRows();
        int totalPages = PageUtil.getTotalPage(totalRows); //总页数
        List<Emp> empList = empDao.getALlEmp(pageIndex);
        map.put("totalPages",totalPages);
        map.put("empList",empList);
        return map;
    }
}
